/* Copyright 2009 Anthony Surma
This file is part of Java's Kademlia Extension (JKADX).

JKADX is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
any later version.

JKADX is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with JKADX.  If not, see <http://www.gnu.org/licenses/>.
 */

package jkadx.networking;

import java.io.*;
import java.net.*;

final class UDPSocketClient
{
    private final DatagramSocket   socket;
    //private final SocketController socketcontroller;
    
    UDPSocketClient( final SocketController socketcontroller, final int outgoingport) throws SocketException
    {  
        //this.socketcontroller = socketcontroller;
        socket = new DatagramSocket(outgoingport);
    }  
    
    void send(final byte[] payload, final InetAddress address, final int port)
           throws IOException
    {
        //DatagramPacket packet = new DatagramPacket(payload, payload.length, address, port);
        //System.out.println("Packet sent to: " + packet.getSocketAddress());
        socket.send(new DatagramPacket(payload, payload.length, address, port));
    }

    void send(final byte[] payload, final InetAddress address, final int port, final int length)
           throws IOException
    {
        //DatagramPacket packet = new DatagramPacket(payload, payload.length, address, port);
        //System.out.println("Packet sent to: " + packet.getSocketAddress());
        socket.send(new DatagramPacket(payload, length, address, port));
    }
}
